/**
 * Created by Administrator on 2017/6/21.
 */

let http = require('http');
let variable = require('../data/variable.js');
let util = require('../util/util.js');
let log = require('../util/log.js');

let request = module.exports;

function httpOpt(path, host, port) {
    if (!host) {
        host = variable.dc.local;
    }
    if (!port) {
        port = variable.dc.http;
    }
    console.log('url:',host,port,path);
    return {
        hostname: host,
        port: port,
        path: path,
        method: 'GET',
        headers: null
        //headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
    };
}
function httpGet(options, cb) {
    http.get(options, function (res) {
        let receiveData = "";
        res.on('data', function (chunk) {
            receiveData += chunk;
        });
        res.on('end', function () {
            cb(JSON.parse(receiveData));
        });
    }).on('error', function (e) {
        cb({'code': 404});
        log.e('404:', e);
    }).end();
}